package com.lg.desireplayer.bandlist;

import android.annotation.SuppressLint;

import java.util.ArrayList;
import java.util.HashMap;

public class BandList {
	@SuppressLint("UseSparseArrays")
	private static final HashMap<Integer, Band> bandList = new HashMap<Integer, Band>();
	
	public static void insertBand(int id, String name, String title,String descr, String image, String media, String link, int likecnt) {
		Band band = new Band();
		band.setId(id);
		band.setName(name);
		band.setTitle(title);
		band.setDescr(descr);
		band.setImage(image);
		band.setMedia(media);
		band.setLink(link);
		band.setLikecnt(likecnt);
		
		bandList.put(id, band);
	}
	
	public static Band retrieveBand(int id) {
		return bandList.get(id);
	}
	
	public static int getSize() {
		return bandList.size();
	}
	
	public static ArrayList<Band> getSortedBandList() {
		ArrayList<Band> sortedBandList = new ArrayList<Band>();
		Band band=null;
		Band tmp;
		for(int i=0 ; i<getSize() ; i++) {
			band = retrieveBand(i);
			sortedBandList.add(band);
		}
		
		//Array List Sorting
		for(int i=0; i<sortedBandList.size()-1;i++)
			for(int j=0; j<sortedBandList.size()-1;j++)
			{
				if(sortedBandList.get(j+1).getLikecnt() > sortedBandList.get(j).getLikecnt())
				{
					tmp = sortedBandList.get(j+1);
					sortedBandList.remove(j+1);
					sortedBandList.add(j+1, sortedBandList.get(j));
					sortedBandList.remove(j);
					sortedBandList.add(j, tmp);
				}
			
			}
		
		return sortedBandList;
	}
}
